//Copyright 2012 Trevin Liberty
//GNU GPL v3
//Author: Trevin Liberty
//
//Base Class of all Entities/Buildings.
//Every instantiate receives it's own UNIQUE ID.

#ifndef DOOHICKEY_H
#define DOOHICKEY_H

#include <cassert>

#include "../Structs.h"
#include "../Point.h"

//SEE: Top of file
class Doohickey {
private:
protected:
	int id;
	static int nextValidID;

	static bitmapImage* healthBar;

	Point<float> pos;
	Point<int> currentMapCellPosition;
	Point<int> imageBound;

	int maxHealthPoints;
	float healthPoints;

	bool selected;
	bool remove;
	bool entity;

	char team;

	Map* map;

	//Draws the current health, as a red/yellow/green bar, underneath the Doohickey
	//	PARAMS:
	//Point<float> cameraPos: Position of the camera
	//Point<int> offset: X/Y offset for drawing
	//int maxLength: Length of the health bar
	void drawHealth(Point<float> cameraPos, Point<int> offset, int maxLength);

public:
	//Constructor
	//	PARAMS:
	//int maxHealth: The maximum/starting amount of health for the doohickey.
	//Map* map: SEE: Structs.h->Struct Map
	//Point<int> imageBound: The bitmap bounds of the doohickey.
	Doohickey(int maxHealth, Map* map, Point<int> imageBound);

	//Returns the unique id of the doohickey.
	int getID() const {return id;}

	//Returns the Doohickeys Screen position.
	Point<float> getPosition() const {return pos;}
	
	//Returns the Doohickeys mapArray index position.
	Point<int> getPosIndex() const {
		return Point<int>(pos.x/map->tileSize, pos.y/map->tileSize);
	}

	//Sets the Doohickeys position.
	//	PARAMS:
	//float x: The x position of the Doohickey. Not a index.
	//float y: The y position of the Doohickey. Not a index.
	void setXY(float x, float y) {pos.x = x; pos.y = y;}

	//Moves the Doohickeys x position by x
	void addToX(float x) {pos.x += x;}

	//Moves the Doohickeys y position by y
	void addToY(float y) {pos.y += y;}

	//Sets the Doohickeys MapCell position(Index). 
	//To keep track of the doohickeys actual map index position.
	void setMapCellPos(Point<int> pos) {currentMapCellPosition = pos;}

	//Returns the Doohickeys Actual mapCell Position.
	Point<int> getMapCellPosition() const {return currentMapCellPosition;}

	//Returns the Doohickeys bitmap bounds.
	Point<int> getImageBound() const {return imageBound;}

	//Adds to the Doohickeys health by t
	void addToHealth(float t) {healthPoints += t;}

	//Returns the Doohickeys current health points.
	float getHealthPoints() const {return healthPoints;}

	//Returns the GameWorld map. SEE: Structs.h->Struct Map{...}
	Map* getMap() {return map;}

	//Sets that the Doohickey is currently selected.
	//Enables drawing of a green circle around the Entity
	void selectTrue() {selected = true;}

	//Sets that the Doohickey is NOT currently selected.
	//Disables drawing of a green circle around the Entity
	void selectFalse() {selected = false;}

	//Returns true if Doohickey is currently selected.
	//	else false;
	bool isSelected() const {return selected;}

	//Return true if the Doohickey needs to be removed from the GameWorld.
	//	AKA deleted
	bool shouldRemove() {return remove;}

	//Returns the Doohickeys team.
	//0 - player, 1 - computer
	int getTeam() const {return team;}

	//Set the Doohickeys team.
	//0 - player, 1 - computer
	void setTeam(char teamID) {team = teamID;}

	//Set that Doohickey is an Entity
	void setIsAEntity() {entity = true;}

	//Returns true if Doohickey is a base class for a Entity
	//	else false
	bool isAEntity() {return entity;}

	//Virtual function used for drawing
	//	PARAMS:
	//Point<float> cameraPos: Camera's position. Used as a offset.
	virtual void draw(Point<float> cameraPos) = 0;

	//Virtual function for updating
	virtual void update() = 0;
};

#endif